package org.tarena.dang.action.user;

import java.sql.SQLException;

import org.tarena.dang.action.BaseAction;
import org.tarena.dang.entity.User;
import org.tarena.dang.service.UserService;
import org.tarena.dang.service.UserServiceImp;

public class RegisterAction extends BaseAction{
	private User user;
	private String number;//验证码
	private String code;//邮箱验证码
	public String execute() throws Exception{
		UserService userService = new UserServiceImp();
		System.out.println("注册邮箱是："+user.getEmail());
		System.out.println("输入的验证码="+number);
		try {
			if(session.get("code").toString().equalsIgnoreCase(number)){
				String ip = httpRequest.getRemoteAddr();
				code = userService.register(user,ip);
				session.put("checkCode", code);
				return "success";
			}else{
				return "error";
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("注册失败！");
			return "error";
		}
		
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
}
